package top.wilbert.collegelink.positionresume.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.wilbert.collegelink.positionresume.entity.PositionEntity;
import top.wilbert.collegelink.positionresume.service.PositionService;
import top.wilbert.collegelink.common.utils.PageUtils;
import top.wilbert.collegelink.common.utils.R;
import top.wilbert.collegelink.positionresume.vo.PositionInfoVo;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * @author Augus
 * @email 2531496343@qq.com
 * @date 2022-12-23 20:02:17
 */
@RestController
@RequestMapping("positionresume/position")
public class PositionController {
    @Autowired
    private PositionService positionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("subject:position:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = positionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 职位的条件查询和模糊查询 动态sql
     */
    @RequestMapping("/listQueryOrFuzzy")
//    @RequiresPermissions("subject:companyposition:list")
    public R listByCompanyId2(@RequestParam Map<String, Object> params, @RequestBody PositionEntity position, @RequestParam("key") String key) {

        List<PositionInfoVo> page = positionService.queryPage(params, position, key);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{positionId}")
//    @RequiresPermissions("subject:position:info")
    public R info(@PathVariable("positionId") Long positionId) {
        PositionEntity position = positionService.getById(positionId);

        return R.ok().put("position", position);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("subject:position:save")
    public R save(@RequestBody PositionEntity position) {
        positionService.save(position);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("subject:position:update")
    public R update(@RequestBody PositionEntity position) {
        positionService.updateById(position);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("subject:position:delete")
    public R delete(@RequestBody Long[] positionIds) {
        positionService.removeByIds(Arrays.asList(positionIds));

        return R.ok();
    }

}
